import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

import java.net.http.HttpRequest;
import java.util.HashMap;

public class testOpenAi {
    public static void main(String[] args) {
        String url = "https://api.openai.com/v1/chat/completions";
        HashMap<String, Object> map = new HashMap<>();
        map.put("model", "gpt-3.5-turbo");
        map.put("messages", "[{\"role\": \"user\", \"content\": \"你好\"}]");
        map.put("temperature", 0.7);
        String json = JSONUtil.toJsonStr(map);
        String result = HttpUtil.createPost(url)
                .body(json)
                .header("Authorization", "Bearer sess-WlnOVs2mqp0zUCQYZyOBBv4gesZ9mJx8KmBedg7Z")
                .execute().body();
        System.out.println(result);
    }
}
